<?php

/**
 * atributos_nuevos actions.
 *
 * @package    auip
 * @subpackage atributos
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class atributos_nuevosActions extends sfActions
{
  public function executeIndex(sfWebRequest $request)
  {
        $this->atributos_nuevos = Doctrine_Core::getTable('Atributos')->createQuery('a')->execute();
  }

public function executeShow(sfWebRequest $request)
  { 
    $this->beca = Doctrine_Core::getTable('Atributos')->find(array($request->getParameter('id')));       
    $this->forward404Unless($this->beca);
  }

  public function executeNew(sfWebRequest $request)
  { 
    $this->form = new AtributosForm();
  }

  public function executeCreate(sfWebRequest $request)
  {
    $this->forward404Unless($request->isMethod(sfRequest::POST));
    
    $nombrebeca = $request->getParameter('nom');
    
    $this->form = new AtributosForm();

    $this->processForm($request, $this->form, $nombrebeca);

    $this->setTemplate('new');
  }

  public function executeEdit(sfWebRequest $request)
  {
        $this->forward404Unless($atributos_nuevos = Doctrine_Core::getTable('Atributos')->find(array($request->getParameter('id'))), sprintf('Object atributos does not exist (%s).', $request->getParameter('id')));
        $this->form = new AtributosForm($atributos_nuevos);
      
  }

  public function executeUpdate(sfWebRequest $request)
  {
    $this->forward404Unless($request->isMethod(sfRequest::POST) || $request->isMethod(sfRequest::PUT));
    $this->forward404Unless($atributos_nuevos = Doctrine_Core::getTable('Atributos')->find(array($request->getParameter('id'))), sprintf('Object atributos_adicionales_beca does not exist (%s).', $request->getParameter('id')));
    $this->form = new AtributosForm($atributos_nuevos);

    $this->processForm($request, $this->form);

    $this->setTemplate('edit');
  }

  public function executeDelete(sfWebRequest $request)
  {
    $request->checkCSRFProtection();

    $this->forward404Unless($atributos_nuevos = Doctrine_Core::getTable('Atributos')->find(array($request->getParameter('id'))), sprintf('Object atributos_adicionales_beca does not exist (%s).', $request->getParameter('id')));
    $atributos_nuevos->delete();

    $this->redirect('atributos_nuevos/index');
  }

  protected function processForm(sfWebRequest $request, sfForm $form, $nombrebeca)
  {
    $form->bind($request->getParameter($form->getName()), $request->getFiles($form->getName()));
    if ($form->isValid())
    {        
        $atributos_nuevos = $form->save();
        $this->getUser()->setAttribute('msg', 'Se ha ADICIONADO un NUEVO item a la convocatoria codigo '.$this->getUser()->getAttribute('id'));
        $this->redirect('atributos_nuevos/new');
    }
  }
}
